import { createReducer } from 'redux-immutablejs'
import Immutable from 'immutable'

import {
	REQUEST_ARTICLES,
	RECEIVE_ARTICLES
} from './actions'

const initialState = Immutable.fromJS({
	datas: [],
	query: {
		version_id: '1.1.0',
		channel_id: 1,
		user_id: 0, 
		limit: 10,
		page: 1
	},
	isMore: true,
	isArticlesFetching: true
})

export default createReducer(initialState, {
	[REQUEST_ARTICLES]: (state, action) => state.set('isArticlesFetching',true),
	[RECEIVE_ARTICLES]: (state, action) => state.merge({
	  	isArticlesFetching: false,
	  	datas: action.articles,
	  	query: action.query
	})
})